package com.eqdd.yiqidian.ui.companyspace

import android.view.View
import com.eqdd.yiqidian.bean.PayFunctionBean
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean
import com.eqdd.yiqidian.kotlin.BaseInfoActivity
import com.eqdd.yiqidian.utils.PayUtil
import kotlinx.android.synthetic.main.activity_recyclerview.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.toast
import java.util.*

/**
 * Created by jhj on 18-7-20.
 */
class PayFunctionActivity : BaseInfoActivity() {

    override val topbar: String
        get() = "企业付费"

    override fun itemClick(p: Int) {

    }

    override fun setEditBeans() {
        val bean = intent.getSerializableExtra("data") as? PayFunctionBean
        bean?.let {
            val array = it.powerEndTime.split("/", " ", ":")
            val current = Calendar.getInstance()
            if (array.size == 6) {
                current.set(array[0].toInt(), array[1].toInt(), array[2].toInt(), array[3].toInt(), array[4].toInt(), array[5].toInt())
            }
            val c = Calendar.getInstance()
            datas.add(SlimEditHintBean("功能", it.modularName, 0))
            datas.add(SlimEditHintBean("描述", it.modularDescribe, 0))
            datas.add(SlimEditHintBean("年限", it.discount, 0))
            datas.add(SlimEditHintBean("价格", it.vipPrice, 0))
            if (it.powerEndTime != null && current.after(c)) {
                datas.add(SlimEditHintBean("截止日期", it.powerEndTime, 0))
                btn_submit.text = "续费"
            } else {
                btn_submit.text = "开通"
            }
            btn_submit.visibility = View.VISIBLE


            var funcType = -1
            if ("留言" == it.modularName) {
                funcType = 3
            } else if ("日志" == it.modularName) {
                funcType = 2
            }
            if (funcType == -1) {
                toast("支付失败")
                return
            }

            btn_submit.onClick { _ ->
                PayUtil.aliPay(this@PayFunctionActivity, "易企点", it.modularName, "企业空间", funcType, it.powerEndTime, it.discount)
                /*bottomCustomDialog(R.layout.list_item_164) { view, dialog ->
                    view.iv_wx.onClick { _ ->
                        dialog.dismiss()
                    }
                    view.iv_ali.onClick { _ ->
                        dialog.dismiss()
                        PayUtil.aliPay(this@PayFunctionActivity, "易企点", it.modularName, "企业空间", funcType, it.powerEndTime, it.discount)
                    }
                }*/
            }
        }
    }
}